<template>
  <section style="height: 100%;">
    <header>
      <a-breadcrumb style="padding: 16px; border-bottom: 1px solid #eee;">
        <a-breadcrumb-item style="cursor: pointer;">
          资源文件管理器
        </a-breadcrumb-item>
      </a-breadcrumb>
    </header>
    <main>
      <div class="entries">
        <div
          v-for="(entry, i) in entries"
          :key="i"
          class="entry"
        >
          <div class="thumbnail">
            <FolderFilled v-if="entry.type ==='folder'" style="font-size: 48px; color: #ffde19;" />
            <FileOutlined v-else style="font-size: 48px;" />
          </div>
          <div class="name" :title="entry.name">
            {{ entry.name }}
          </div>
        </div>
      </div>
    </main>
  </section>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted } from 'vue'
import { FolderFilled, FileOutlined } from '@ant-design/icons-vue';
import useResourceStore from '@/store/resource';

export default defineComponent({
  components: { FolderFilled, FileOutlined },
  setup() {
    const resourceStore = useResourceStore();
    const entries = computed(() => resourceStore.entries);

    onMounted(() => resourceStore.listChildren('/'));

    return {
      entries,
    };
  },
})
</script>

<style lang="less">
#app {
  height: 100%;
}
</style>

<style lang="less" scoped>
@import '~ant-design-vue/lib/style/themes/default.less';

.entries {
  height: calc(100% - 54px);
  overflow: auto;
  padding: 1em;
}
.entry {
  margin: 10px;
  display: inline-block;

  &.dragover {
    background-color: @primary-3;
  }

  .thumbnail {
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    overflow: hidden;

    & > * {
      vertical-align: middle;
    }
  }

  .name {
    width: 100px;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
